(function(angular) {
	'use strict';
	angular.module('fs.waf').controller('cda.jobGroup.viewController', viewController);
	viewController.$inject = [ '$scope', 'Constants', 'layoutConfig', 'modalService', 'validatorConfig', 'gridService', 'authService', 'jobGroupService' ];
	function viewController($scope, Constants, layoutConfig, modalService, validatorConfig, gridService, authService, jobGroupService) {
		var ctrl = this, jobGroupInfo = $scope.$stateParams.params;
		ctrl.layoutConfig = layoutConfig;
		ctrl.validatorConfig = validatorConfig;
		ctrl.jobGroup = {};
		ctrl.jobGroup.jobgrpDepencyList = ctrl.jobGroup.jobgrpDepencyList || [];
		ctrl.jobGroup.jobgrpSchd = ctrl.jobGroup.jobgrpSchd || {};
		ctrl.jobGroup.jobGroupPreParmetes = ctrl.jobGroup.jobGroupPreParmetes || [];
		ctrl.jobGroup.jobGroupPostParmetes = ctrl.jobGroup.jobGroupPostParmetes || [];
		ctrl.init = function() {
			var params = {
				jobGroupId : jobGroupInfo.jobGroupId
			};
			ctrl.innerGridOptions = gridService.createInnerGridOptions($scope, ctrl.layoutConfig.formConfigs.jobgrpDepency.tableConfigs.table);
			ctrl.innerGridOptions.data = 'vm.jobGroup.jobgrpDepencyList';
			ctrl.innerGridOptions.enableRowHeaderSelection = false;
			
			ctrl.jobPreParmetesOptions = gridService.createInnerGridOptions($scope, ctrl.layoutConfig.formConfigs.jobGroupPreParameters.tableConfigs.table);
			ctrl.jobPreParmetesOptions.data = 'vm.jobGroup.jobGroupPreParmetes';
			ctrl.jobPreParmetesOptions.enableRowHeaderSelection = false;
			
			ctrl.jobPostParmetesOptions = gridService.createInnerGridOptions($scope, ctrl.layoutConfig.formConfigs.jobGroupPostParameters.tableConfigs.table);
			ctrl.jobPostParmetesOptions.data = 'vm.jobGroup.jobGroupPostParmetes';
			ctrl.jobPostParmetesOptions.enableRowHeaderSelection = false;
			
			jobGroupService.initDataOptions(ctrl);
			return authService.view(params).then(function(response) {
				ctrl.jobGroup = response.data || jobGroupInfo;
				ctrl.jobGroup.jobgrpDepencyList = ctrl.jobGroup.jobgrpDepencyList || [];
				ctrl.jobGroup.jobgrpSchd = ctrl.jobGroup.jobgrpSchd || {};
				ctrl.jobGroup.jobGroupPreParmetes = ctrl.jobGroup.jobGroupPreParmetes || [];
				ctrl.jobGroup.jobGroupPostParmetes = ctrl.jobGroup.jobGroupPostParmetes || [];
			}, angular.noop);
		};
		
		ctrl.viewJobs = function(){
			modalService.openCustomDialogs({
				'dialogsModule' : 'cda.job',
				'title' : 'button.text.jobs',
				'params' : jobGroupInfo
			});
		}
	}
})(angular);